﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Net;
using System.Collections;
using System.Xml;
using System.Linq;
//using System.Xml.Linq;

using CommonUtils;
using TDAL = EzDAL.Auto2;
using TDALUtils = EzDAL.Utils;
using TConst = TERP.Constants;
using TUtils = TERP.Utils;
using TError = TERP.Errors;

namespace TERP.BizITS
{
    public partial class BizWater
	{
		//#region // Private Utils:
		//#endregion

		//#region // Private Core:
		//#endregion

		#region // Private Utils:
		private void mySys_CheckUser(
			ref ArrayList alParamsCoupleError
			, string strUserCode
			, string strFlagExistToCheck
			, string strFlagActiveListToCheck
			, out DataTable dt_Sys_User
			)
		{
			// GetInfo:
			dt_Sys_User = TDALUtils.DBUtils.GetTableContents(
				_dbCarSv // db
				, "Sys_User" // strTableName
				, "*" // strColumnList
				, "" // strClauseOrderBy
				, "UserCode", "=", strUserCode // arrobjParamsTriple item
				);

			// strFlagExistToCheck:
			if (strFlagExistToCheck.Length > 0)
			{
				if (StringUtils.StringEqual(strFlagExistToCheck, TConst.Flag.Active) && dt_Sys_User.Rows.Count < 1)
				{
					alParamsCoupleError.AddRange(new object[]{
						"UserCodeNotFound", strUserCode
						});
					throw CMyException.Raise(
						TError.ErrITS.CommonAppData_SysUserNotFound
						, null
						, alParamsCoupleError.ToArray()
						);
				}
				if (StringUtils.StringEqual(strFlagExistToCheck, TConst.Flag.Inactive) && dt_Sys_User.Rows.Count > 0)
				{
					alParamsCoupleError.AddRange(new object[]{
						"UserCodeFound", strUserCode
						});
					throw CMyException.Raise(
						TError.ErrITS.CommonAppData_SysUserFound
						, null
						, alParamsCoupleError.ToArray()
						);
				}
			}

			// strFlagActiveListToCheck:
			if (strFlagActiveListToCheck.Length > 0 && !strFlagActiveListToCheck.Contains(Convert.ToString(dt_Sys_User.Rows[0]["FlagActive"])))
			{
				alParamsCoupleError.AddRange(new object[]{
					"UserCodeError", strUserCode
					, "FlagActiveListToCheck", strFlagActiveListToCheck
					, "FlagActiveCurrent", dt_Sys_User.Rows[0]["FlagActive"]
					});
				throw CMyException.Raise(
					TError.ErrITS.CommonAppData_SysUserInvalidFlagActive
					, null
					, alParamsCoupleError.ToArray()
					);
			}
		}
		private void mySys_GetMapSysUserSysObject(
			ref ArrayList alParamsCoupleError
			, string strUserCodeList
			, string strUserNamePattern
			, string strFlagActiveListForUser
			, string strBUCodeList
			, string strBUCodePattern
			, string strFlagActiveListForDealer
			, string strGroupCodeList
			, string strPartnerCodeList
			, string strObjectCodeList
			, string strObjectTypeList
			, string strFlagActiveListForObject
			, out DataTable dt_Map_SU_SO
			)
		{
			#region // Build Sql:
			ArrayList alParamsCoupleSql = new ArrayList();
			string strSqlGetData = StringUtils.Replace(@"
						-- #tbl_Map_SU_SO_Filter:
						select distinct
							t.UserCode, msgso.ObjectCode, t.FlagActive
						into #tbl_Map_SU_SO_Filter
						from Sys_User t with (nolock)
							--inner join Mst_Dealer md with (nolock)
							--	on t.DealerCode = md.DealerCode
							inner join Sys_MapUserGroup msgsu with (nolock)
								on t.UserCode = msgsu.UserCode
							inner join Sys_MapGroupObject msgso with (nolock)
								on msgsu.GroupCode = msgso.GroupCode
							inner join Sys_Object so with (nolock)
								on msgso.ObjectCode = so.ObjectCode -- and (t.DealerCode = so.DealerCode )DatNL - 12/11/2010 - Update cho rieng Service
						where (1=1)
							zzzzClauseWhere_strUserCodeList							
							zzzzClauseWhere_strUserNamePattern
							zzzzClauseWhere_strFlagActiveListForUser
							zzzzClauseWhere_strBUCodeList
							zzzzClauseWhere_strBUCodePattern
							zzzzClauseWhere_strFlagActiveListForDealer
							zzzzClauseWhere_strGroupCodeList
							zzzzClauseWhere_strObjectCodeList
							zzzzClauseWhere_strFlagActiveListForObject
						;

						-- Map_SU_SO:
						select
							zzzzClauseColumnForSysUserInfo
							, zzzzClauseColumnForSysObjectInfo
						from #tbl_Map_SU_SO_Filter t with (nolock)
							inner join Sys_User su with (nolock)
								on t.UserCode = su.UserCode
							inner join Sys_Object so with (nolock)
								on t.ObjectCode = so.ObjectCode
						;
				"
                , "zzzzClauseColumnForSysUserInfo", mySql_GetClauseColumnForSysUserInfo("su.")
				, "zzzzClauseColumnForSysObjectInfo", mySql_GetClauseColumnForSysObjectInfo("so.")
				);

			string zzzzClauseWhere_strUserCodeList = SqlUtils.BuildClauseConditionList("and", "t.UserCode", strUserCodeList, "|");
			
			string zzzzClauseWhere_strUserNamePattern = SqlUtils.BuildClauseConditionSingle("and", "t.UserName", "like", "@strUserNamePattern", strUserNamePattern, ref alParamsCoupleSql);
            //string zzzzClauseWhere_strFlagSysAdminList = SqlUtils.BuildClauseConditionList("and", "t.FlagSysAdmin", strFlagSysAdminList, "|");
			string zzzzClauseWhere_strFlagActiveListForUser = SqlUtils.BuildClauseConditionList("and", "t.FlagActive", strFlagActiveListForUser, "|");
			string zzzzClauseWhere_strBUCodeList = SqlUtils.BuildClauseConditionList("and", "md.BUCode", strBUCodeList, "|");
			string zzzzClauseWhere_strBUCodePattern = SqlUtils.BuildClauseConditionSingle("and", "md.BUCode", "like", "@strBUCodePattern", strBUCodePattern, ref alParamsCoupleSql);
			string zzzzClauseWhere_strFlagActiveListForDealer = SqlUtils.BuildClauseConditionList("and", "md.FlagActive", strFlagActiveListForDealer, "|");
			string zzzzClauseWhere_strGroupCodeList = SqlUtils.BuildClauseConditionList("and", "msgsu.GroupCode", strGroupCodeList, "|");
			string zzzzClauseWhere_strObjectCodeList = SqlUtils.BuildClauseConditionList("and", "msgso.ObjectCode", strObjectCodeList, "|");
			string zzzzClauseWhere_strFlagActiveListForObject = SqlUtils.BuildClauseConditionList("and", "so.FlagActive", strFlagActiveListForObject, "|");

			strSqlGetData = StringUtils.Replace(
				strSqlGetData
				, "zzzzClauseWhere_strUserCodeList", zzzzClauseWhere_strUserCodeList
				, "zzzzClauseWhere_strUserNamePattern", zzzzClauseWhere_strUserNamePattern
				, "zzzzClauseWhere_strFlagActiveListForUser", zzzzClauseWhere_strFlagActiveListForUser
				, "zzzzClauseWhere_strBUCodeList", zzzzClauseWhere_strBUCodeList
				, "zzzzClauseWhere_strBUCodePattern", zzzzClauseWhere_strBUCodePattern
				, "zzzzClauseWhere_strFlagActiveListForDealer", zzzzClauseWhere_strFlagActiveListForDealer
				, "zzzzClauseWhere_strGroupCodeList", zzzzClauseWhere_strGroupCodeList
				, "zzzzClauseWhere_strObjectCodeList", zzzzClauseWhere_strObjectCodeList
				, "zzzzClauseWhere_strFlagActiveListForObject", zzzzClauseWhere_strFlagActiveListForObject
				);
			#endregion

			#region // Get Data:
			myDebug_SaveSql(
				_bDebugMode // bDebugMode
				, ref alParamsCoupleError // alParamsCoupleError
				, string.Format("strSql_{0}", "mySys_GetMapSysUserSysObject") // strParamName
				, strSqlGetData // strSql
				);
			DataSet dsGetData = _dbCarSv.ExecQuery(
				strSqlGetData
				, alParamsCoupleSql.ToArray()
				);
			dsGetData.Tables[0].TableName = "Map_SU_SO";
			dt_Map_SU_SO = dsGetData.Tables[0];
			#endregion
		}
		#endregion

		#region // Public Ser_System:
		public DataSet Ser_SysGetCurentUser(
			string strGWUserCode
			, string strGWPassword
			, string strTid
			, string strPartnerCode
			, string strPartnerUserCode
			, string strLanguageCode
			)
		{
			#region // Temp:
			DataSet mdsFinal = CMyDataSet.NewMyDataSet(strTid);
			int nTidSeq = 0;
			bool bNeedTransaction = false;
			string strFunctionName = "Ser_SysGetCurentUser";
			string strErrorCodeDefault = TError.ErrITS.Ser_SysGetCurentUser;
			ArrayList alParamsCoupleError = new ArrayList(new object[]{
					"strFunctionName", strFunctionName
					});
			#endregion

			try
			{
				#region // Init:
				_dbCarSv.AppUserID = strPartnerUserCode;
				if (bNeedTransaction) _dbCarSv.BeginTransaction();

				// Write request log:
				_log.WriteLogAsync(
					strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strTid // strAppTid
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, TError.Error.NoError // strAppErrorCode
					, strFunctionName // strAppLogType1
					, "REQUEST" // strAppLogType2
					, "" // strAppLogType3
					, strLanguageCode // strAppLanguageCode
					, "" // strAppRemark
					, TUtils.CUtils.ParamsCouple2ParamsTriple(alParamsCoupleError, 1, "").ToArray() // arrobjParamsTriple
					);

				// Check Valid Tid:
				myUtils_ValidateId(
					ref alParamsCoupleError // alParamsCoupleError
					, strTid // strTid
					, TError.ErrITS.CommonInvalidTid // strErrCodeWhenInvalid
					);
				#endregion

				#region // Build Sql:
				ArrayList alParamsCoupleSql = new ArrayList();
				string strSqlGetData = StringUtils.Replace(@"
						select t.*
						from Sys_User t with (nolock)
						where (1=1)
							zzzzClauseWhere_strUserCode
						;
					"
					);

				string zzzzClauseWhere_strUserCode = SqlUtils.BuildClauseConditionList("and", "t.UserCode", strPartnerUserCode, "|");

				strSqlGetData = StringUtils.Replace(
					strSqlGetData
					, "zzzzClauseWhere_strUserCode", zzzzClauseWhere_strUserCode
					);
				#endregion

				#region // Get Data:
				myDebug_SaveSql(
					_bDebugMode // bDebugMode
					, ref alParamsCoupleError // alParamsCoupleError
					, string.Format("strSql_{0}", strFunctionName) // strParamName
					, strSqlGetData // strSql
					);
				DataSet dsGetData = _dbCarSv.ExecQuery(
					strSqlGetData
					, alParamsCoupleSql.ToArray()
					);
				dsGetData.Tables[0].TableName = "Sys_User";
				DataUtils.MoveDataTable(ref mdsFinal, ref dsGetData);
				#endregion

				// Return Good:
				TDALUtils.DBUtils.CommitSafety(_dbCarSv);
				mdsFinal.AcceptChanges();
				return mdsFinal;
			}
			catch (Exception exc)
			{
				#region // Catch of try:
				// Rollback:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);

				// Return Bad:
				return TUtils.CProcessException.Process(
					ref mdsFinal
					, exc
					, strErrorCodeDefault
					, alParamsCoupleError.ToArray()
					);
				#endregion
			}
			finally
			{
				#region // Finally of try:
				// Rollback and Release resources:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);
				TDALUtils.DBUtils.ReleaseAllSemaphore(_dbCarSv_Sys, true);

				TUtils.CProcessException.Process(
					ref mdsFinal // mdsFinal
					, _log // log
					, strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strFunctionName // strFunctionName
					, TUtils.CUtils.TidNext(strTid, ref nTidSeq) // strAppTid
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, strLanguageCode // strLanguageCode
					, "" // strRemark
					);
				#endregion
			}
		}

		public DataSet Ser_SysGetUser(
			string strGWUserCode
			, string strGWPassword
			, string strTid
			, string strPartnerCode
			, string strPartnerUserCode
			, string strLanguageCode
			, string strUserCodeList
			, string strUserNamePattern
			, string strFlagActiveListForUser
			, string strAreaCodeList
			, string strBUCodeList
			, string strBUCodePattern
			, string strFlagActiveListForDealer
			, string strGroupCodeList
			)
		{
			#region // Temp:
			DataSet mdsFinal = CMyDataSet.NewMyDataSet(strTid);
			int nTidSeq = 0;
			bool bNeedTransaction = false;
			string strFunctionName = "Ser_SysGetUser";
			string strErrorCodeDefault = TError.ErrITS.Ser_SysGetUser;
			ArrayList alParamsCoupleError = new ArrayList(new object[]{
					"strFunctionName", strFunctionName
					, "strUserCodeList", strUserCodeList
					, "strUserNamePattern", strUserNamePattern
					, "strFlagActiveListForUser", strFlagActiveListForUser
                    //, "strDealerCode", strDealerCodeList
                    //, "strDealerTypeList", strDealerTypeList
					, "strAreaCodeList", strAreaCodeList
					, "strBUCodeList", strBUCodeList
					, "strBUCodePattern", strBUCodePattern
					, "strFlagActiveListForDealer", strFlagActiveListForDealer
					, "strGroupCodeList", strGroupCodeList
					});
			#endregion

			try
			{
				#region // Init:
				_dbCarSv.AppUserID = strPartnerUserCode;
				if (bNeedTransaction) _dbCarSv.BeginTransaction();

				// Write request log:
				_log.WriteLogAsync(
					strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strTid // strAppTid
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, TError.Error.NoError // strAppErrorCode
					, strFunctionName // strAppLogType1
					, "REQUEST" // strAppLogType2
					, "" // strAppLogType3
					, strLanguageCode // strAppLanguageCode
					, "" // strAppRemark
					, TUtils.CUtils.ParamsCouple2ParamsTriple(alParamsCoupleError, 1, "").ToArray() // arrobjParamsTriple
					);

				// Check Valid Tid:
				myUtils_ValidateId(
					ref alParamsCoupleError // alParamsCoupleError
					, strTid // strTid
					, TError.ErrITS.CommonInvalidTid // strErrCodeWhenInvalid
					);
				#endregion

				#region // Build Sql:
				ArrayList alParamsCoupleSql = new ArrayList();
				string strSqlGetData = StringUtils.Replace(@"
						-- #tbl_Sys_User_Filter:
						select distinct
							t.UserCode
						into #tbl_Sys_User_Filter
						from Sys_User t with (nolock)
							--inner join Mst_Dealer md with (nolock)
								--on t.DealerCode = md.DealerCode
							left join Sys_MapUserGroup msgsu with (nolock)
								on t.UserCode = msgsu.UserCode
						where (1=1)
							zzzzClauseWhere_strUserCodeList
							zzzzClauseWhere_strUserNamePattern
							zzzzClauseWhere_strFlagActiveListForUser
							zzzzClauseWhere_strAreaCodeList
							zzzzClauseWhere_strBUCodeList
							zzzzClauseWhere_strBUCodePattern
							zzzzClauseWhere_strFlagActiveListForDealer
							zzzzClauseWhere_strGroupCodeList
						;

						-- Sys_User:
						select
							zzzzClauseColumnForSysUserInfo
							--, md.*
						from Sys_User t with (nolock)
							inner join #tbl_Sys_User_Filter su_f with (nolock)
								on t.UserCode = su_f.UserCode
							--inner join Mst_Dealer md with (nolock)
								--on t.DealerCode = md.DealerCode
						--where (1=1)
						;
					"
                    , "zzzzClauseColumnForSysUserInfo", mySql_GetClauseColumnForSysUserInfo("t.")
					);

				string zzzzClauseWhere_strUserCodeList = SqlUtils.BuildClauseConditionList("and", "t.UserCode", strUserCodeList, "|");
				string zzzzClauseWhere_strUserNamePattern = SqlUtils.BuildClauseConditionSingle("and", "t.UserName", "like", "@strUserNamePattern", strUserNamePattern, ref alParamsCoupleSql);
				string zzzzClauseWhere_strFlagActiveListForUser = SqlUtils.BuildClauseConditionList("and", "t.FlagActive", strFlagActiveListForUser, "|");
                //string zzzzClauseWhere_strDealerCodeList = SqlUtils.BuildClauseConditionList("and", "t.DealerCode", strDealerCodeList, "|");
                //string zzzzClauseWhere_strDealerTypeList = SqlUtils.BuildClauseConditionList("and", "md.DealerType", strDealerTypeList, "|");
				string zzzzClauseWhere_strAreaCodeList = SqlUtils.BuildClauseConditionList("and", "md.AreaCode", strAreaCodeList, "|");
				string zzzzClauseWhere_strBUCodeList = SqlUtils.BuildClauseConditionList("and", "md.BUCode", strBUCodeList, "|");
				string zzzzClauseWhere_strBUCodePattern = SqlUtils.BuildClauseConditionSingle("and", "md.BUCode", "like", "@strBUCodePattern", strBUCodePattern, ref alParamsCoupleSql);
				string zzzzClauseWhere_strFlagActiveListForDealer = SqlUtils.BuildClauseConditionList("and", "md.FlagActive", strFlagActiveListForDealer, "|");
				string zzzzClauseWhere_strGroupCodeList = SqlUtils.BuildClauseConditionList("and", "msgsu.GroupCode", strGroupCodeList, "|");

				strSqlGetData = StringUtils.Replace(
					strSqlGetData
					, "zzzzClauseWhere_strUserCodeList", zzzzClauseWhere_strUserCodeList
					, "zzzzClauseWhere_strUserNamePattern", zzzzClauseWhere_strUserNamePattern
					, "zzzzClauseWhere_strFlagActiveListForUser", zzzzClauseWhere_strFlagActiveListForUser
                    //, "zzzzClauseWhere_strDealerCodeList", zzzzClauseWhere_strDealerCodeList
                    //, "zzzzClauseWhere_strDealerTypeList", zzzzClauseWhere_strDealerTypeList
					, "zzzzClauseWhere_strAreaCodeList", zzzzClauseWhere_strAreaCodeList
					, "zzzzClauseWhere_strBUCodeList", zzzzClauseWhere_strBUCodeList
					, "zzzzClauseWhere_strBUCodePattern", zzzzClauseWhere_strBUCodePattern
					, "zzzzClauseWhere_strFlagActiveListForDealer", zzzzClauseWhere_strFlagActiveListForDealer
					, "zzzzClauseWhere_strGroupCodeList", zzzzClauseWhere_strGroupCodeList
					);
				#endregion

				#region // Get Data:
				myDebug_SaveSql(
					_bDebugMode // bDebugMode
					, ref alParamsCoupleError // alParamsCoupleError
					, string.Format("strSql_{0}", strFunctionName) // strParamName
					, strSqlGetData // strSql
					);
				DataSet dsGetData = _dbCarSv.ExecQuery(
					strSqlGetData
					, alParamsCoupleSql.ToArray()
					);
				dsGetData.Tables[0].TableName = "Sys_User";
				DataUtils.MoveDataTable(ref mdsFinal, ref dsGetData);
				#endregion

				// Return Good:
				TDALUtils.DBUtils.CommitSafety(_dbCarSv);
				mdsFinal.AcceptChanges();
				return mdsFinal;
			}
			catch (Exception exc)
			{
				#region // Catch of try:
				// Rollback:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);

				// Return Bad:
				return TUtils.CProcessException.Process(
					ref mdsFinal
					, exc
					, strErrorCodeDefault
					, alParamsCoupleError.ToArray()
					);
				#endregion
			}
			finally
			{
				#region // Finally of try:
				// Rollback and Release resources:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);
				TDALUtils.DBUtils.ReleaseAllSemaphore(_dbCarSv_Sys, true);

				TUtils.CProcessException.Process(
					ref mdsFinal // mdsFinal
					, _log // log
					, strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strFunctionName // strFunctionName
					, TUtils.CUtils.TidNext(strTid, ref nTidSeq) // strAppTid
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, strLanguageCode // strLanguageCode
					, "" // strRemark
					);
				#endregion
			}
		}
		public DataSet Ser_SysGetGroup(
			string strGWUserCode
			, string strGWPassword
			, string strTid
			, string strPartnerCode
			, string strPartnerUserCode
			, string strLanguageCode
			, string strGroupCodeList
			, string strGroupNamePattern
			)
		{
			#region // Temp:
			DataSet mdsFinal = CMyDataSet.NewMyDataSet(strTid);
			int nTidSeq = 0;
			bool bNeedTransaction = false;
			string strFunctionName = "Ser_SysGetGroup";
			string strErrorCodeDefault = TError.ErrITS.Ser_SysGetGroup;
			ArrayList alParamsCoupleError = new ArrayList(new object[]{
					"strFunctionName", strFunctionName
					, "strGroupCodeList", strGroupCodeList
					, "strGroupNamePattern", strGroupNamePattern
					});
			#endregion

			try
			{
				#region // Init:
				_dbCarSv.AppUserID = strPartnerUserCode;
				if (bNeedTransaction) _dbCarSv.BeginTransaction();

				// Write request log:
				_log.WriteLogAsync(
					strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strTid // strAppTid
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, TError.Error.NoError // strAppErrorCode
					, strFunctionName // strAppLogType1
					, "REQUEST" // strAppLogType2
					, "" // strAppLogType3
					, strLanguageCode // strAppLanguageCode
					, "" // strAppRemark
					, TUtils.CUtils.ParamsCouple2ParamsTriple(alParamsCoupleError, 1, "").ToArray() // arrobjParamsTriple
					);

				// Check Valid Tid:
				myUtils_ValidateId(
					ref alParamsCoupleError // alParamsCoupleError
					, strTid // strTid
					, TError.ErrITS.CommonInvalidTid // strErrCodeWhenInvalid
					);
				#endregion

				#region // Build Sql:
				ArrayList alParamsCoupleSql = new ArrayList();
				string strSqlGetData = @"
						select
							t.GroupCode
							, t.GroupName
						from Sys_Group t with (nolock)
						where (1=1)
							zzzzClauseWhereGroupCodeList
							zzzzClauseWhereGroupNamePattern
						;
					";
				string zzzzClauseWhereGroupCodeList = SqlUtils.BuildClauseConditionList("and", "t.GroupCode", strGroupCodeList, "|");
				string zzzzClauseWhereGroupNamePattern = SqlUtils.BuildClauseConditionSingle("and", "t.GroupName", "like", "@strGroupNamePattern", strGroupNamePattern, ref alParamsCoupleSql);
				strSqlGetData = StringUtils.Replace(
					strSqlGetData
					, "zzzzClauseWhereGroupCodeList", zzzzClauseWhereGroupCodeList
					, "zzzzClauseWhereGroupNamePattern", zzzzClauseWhereGroupNamePattern
					);
				#endregion

				#region // Get Data:
				myDebug_SaveSql(
					_bDebugMode // bDebugMode
					, ref alParamsCoupleError // alParamsCoupleError
					, string.Format("strSql_{0}", strFunctionName) // strParamName
					, strSqlGetData // strSql
					);
				DataSet dsGetData = _dbCarSv.ExecQuery(
					strSqlGetData
					, alParamsCoupleSql.ToArray()
					);
				dsGetData.Tables[0].TableName = "Sys_Group";
				DataUtils.MoveDataTable(ref mdsFinal, ref dsGetData);
				#endregion

				// Return Good:
				TDALUtils.DBUtils.CommitSafety(_dbCarSv);
				mdsFinal.AcceptChanges();
				return mdsFinal;
			}
			catch (Exception exc)
			{
				#region // Catch of try:
				// Rollback:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);

				// Return Bad:
				return TUtils.CProcessException.Process(
					ref mdsFinal
					, exc
					, strErrorCodeDefault
					, alParamsCoupleError.ToArray()
					);
				#endregion
			}
			finally
			{
				#region // Finally of try:
				// Rollback and Release resources:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);
				TDALUtils.DBUtils.ReleaseAllSemaphore(_dbCarSv_Sys, true);

				TUtils.CProcessException.Process(
					ref mdsFinal // mdsFinal
					, _log // log
					, strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strFunctionName // strFunctionName
					, TUtils.CUtils.TidNext(strTid, ref nTidSeq) // strAppTid
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, strLanguageCode // strLanguageCode
					, "" // strRemark
					);
				#endregion
			}
		}
		public DataSet Ser_SysGetMapSysGroupSysUser(
			string strGWUserCode
			, string strGWPassword
			, string strTid
			, string strPartnerCode
			, string strPartnerUserCode
			, string strLanguageCode
			, string strGroupCodeList
			, string strUserCodeList
			, string strFlagActiveListForUser
			)
		{
			#region // Temp:
			DataSet mdsFinal = CMyDataSet.NewMyDataSet(strTid);
			int nTidSeq = 0;
			bool bNeedTransaction = false;
			string strFunctionName = "Ser_SysGetMapSysGroupSysUser";
			string strErrorCodeDefault = TError.ErrITS.Ser_SysGetMapSysGroupSysUser;
			ArrayList alParamsCoupleError = new ArrayList(new object[]{
					"strFunctionName", strFunctionName
					, "strGroupCodeList", strGroupCodeList
					, "strUserCodeList", strUserCodeList
					, "strFlagActiveListForUser", strFlagActiveListForUser
                    //, "strDealerCode", strDealerCodeList
					});
			#endregion

			try
			{
				#region // Init:
				_dbCarSv.AppUserID = strPartnerUserCode;
				if (bNeedTransaction) _dbCarSv.BeginTransaction();

				// Write request log:
				_log.WriteLogAsync(
					strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strTid // strAppTid
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, TError.Error.NoError // strAppErrorCode
					, strFunctionName // strAppLogType1
					, "REQUEST" // strAppLogType2
					, "" // strAppLogType3
					, strLanguageCode // strAppLanguageCode
					, "" // strAppRemark
					, TUtils.CUtils.ParamsCouple2ParamsTriple(alParamsCoupleError, 1, "").ToArray() // arrobjParamsTriple
					);

				// Check Valid Tid:
				myUtils_ValidateId(
					ref alParamsCoupleError // alParamsCoupleError
					, strTid // strTid
					, TError.ErrITS.CommonInvalidTid // strErrCodeWhenInvalid
					);
				#endregion

				#region // Build Sql:
				ArrayList alParamsCoupleSql = new ArrayList();
				string strSqlGetData = StringUtils.Replace(@"
						select
							zzzzClauseColumnForSysUserInfo
							, sg.GroupCode
							, sg.GroupName
						from Sys_MapUserGroup t with (nolock)
							inner join Sys_User su with (nolock)
								on t.UserCode = su.UserCode
							inner join Sys_Group sg with (nolock)
								on t.GroupCode = sg.GroupCode
						where (1=1)
							zzzzClauseWhereGroupCodeList
							zzzzClauseWhereUserCodeList
							zzzzClauseWhereFlagActiveListForUser

						;
					"
                    , "zzzzClauseColumnForSysUserInfo", mySql_GetClauseColumnForSysUserInfo("su.")
					);
				string zzzzClauseWhereGroupCodeList = SqlUtils.BuildClauseConditionList("and", "t.GroupCode", strGroupCodeList, "|");
				string zzzzClauseWhereUserCodeList = SqlUtils.BuildClauseConditionList("and", "t.UserCode", strUserCodeList, "|");
				string zzzzClauseWhereFlagActiveListForUser = SqlUtils.BuildClauseConditionList("and", "su.FlagActive", strFlagActiveListForUser, "|");
                //string zzzzClauseWhereDealerCodeList = SqlUtils.BuildClauseConditionList("and", "sg.DealerCode", strDealerCodeList, "|");
				strSqlGetData = StringUtils.Replace(
					strSqlGetData
					, "zzzzClauseWhereGroupCodeList", zzzzClauseWhereGroupCodeList
					, "zzzzClauseWhereUserCodeList", zzzzClauseWhereUserCodeList
					, "zzzzClauseWhereFlagActiveListForUser", zzzzClauseWhereFlagActiveListForUser
                    //, "zzzzClauseWhereDealerCodeList", zzzzClauseWhereDealerCodeList
					);
				#endregion

				#region // Get Data:
				myDebug_SaveSql(
					_bDebugMode // bDebugMode
					, ref alParamsCoupleError // alParamsCoupleError
					, string.Format("strSql_{0}", strFunctionName) // strParamName
					, strSqlGetData // strSql
					);
				DataSet dsGetData = _dbCarSv.ExecQuery(
					strSqlGetData
					, alParamsCoupleSql.ToArray()
					);
				dsGetData.Tables[0].TableName = "Map_SG_SU";
				DataUtils.MoveDataTable(ref mdsFinal, ref dsGetData);
				#endregion

				// Return Good:
				TDALUtils.DBUtils.CommitSafety(_dbCarSv);
				mdsFinal.AcceptChanges();
				return mdsFinal;
			}
			catch (Exception exc)
			{
				#region // Catch of try:
				// Rollback:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);

				// Return Bad:
				return TUtils.CProcessException.Process(
					ref mdsFinal
					, exc
					, strErrorCodeDefault
					, alParamsCoupleError.ToArray()
					);
				#endregion
			}
			finally
			{
				#region // Finally of try:
				// Rollback and Release resources:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);
				TDALUtils.DBUtils.ReleaseAllSemaphore(_dbCarSv_Sys, true);

				TUtils.CProcessException.Process(
					ref mdsFinal // mdsFinal
					, _log // log
					, strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strFunctionName // strFunctionName
					, TUtils.CUtils.TidNext(strTid, ref nTidSeq) // strAppTid
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, strLanguageCode // strLanguageCode
					, "" // strRemark
					);
				#endregion
			}
		}
		public DataSet Ser_SysGetPartner(
			string strGWUserCode
			, string strGWPassword
			, string strTid
			, string strPartnerCode
			, string strPartnerUserCode
			, string strLanguageCode
			, string strPartnerCodeList
			, string strDealerCodeList
			)
		{
			#region // Temp:
			DataSet mdsFinal = CMyDataSet.NewMyDataSet(strTid);
			int nTidSeq = 0;
			bool bNeedTransaction = false;
			string strFunctionName = "Ser_SysGetPartner";
			string strErrorCodeDefault = TError.ErrITS.Ser_SysGetPartner;
			ArrayList alParamsCoupleError = new ArrayList(new object[]{
					"strFunctionName", strFunctionName
					, "strPartnerCodeList", strPartnerCodeList
					});
			#endregion

			try
			{
				#region // Init:
				_dbCarSv.AppUserID = strPartnerUserCode;
				if (bNeedTransaction) _dbCarSv.BeginTransaction();

				// Write request log:
				_log.WriteLogAsync(
					strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strTid // strAppTid
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, TError.Error.NoError // strAppErrorCode
					, strFunctionName // strAppLogType1
					, "REQUEST" // strAppLogType2
					, "" // strAppLogType3
					, strLanguageCode // strAppLanguageCode
					, "" // strAppRemark
					, TUtils.CUtils.ParamsCouple2ParamsTriple(alParamsCoupleError, 1, "").ToArray() // arrobjParamsTriple
					);

				// Check Valid Tid:
				myUtils_ValidateId(
					ref alParamsCoupleError // alParamsCoupleError
					, strTid // strTid
					, TError.ErrITS.CommonInvalidTid // strErrCodeWhenInvalid
					);
				#endregion

				#region // Build Sql:
				ArrayList alParamsCoupleSql = new ArrayList();
				string strSqlGetData = @"
						select
							t.PartnerCode
							, t.PartnerName
						from Sys_Partner t with (nolock)
						where (1=1)
							zzzzClauseWherePartnerCodeList
						;
					";
				string zzzzClauseWherePartnerCodeList = SqlUtils.BuildClauseConditionList("and", "t.PartnerCode", strPartnerCodeList, "|");
				strSqlGetData = StringUtils.Replace(
					strSqlGetData
					, "zzzzClauseWherePartnerCodeList", zzzzClauseWherePartnerCodeList
					);
				#endregion

				#region // Get Data:
				myDebug_SaveSql(
					_bDebugMode // bDebugMode
					, ref alParamsCoupleError // alParamsCoupleError
					, string.Format("strSql_{0}", strFunctionName) // strParamName
					, strSqlGetData // strSql
					);
				DataSet dsGetData = _dbCarSv.ExecQuery(
					strSqlGetData
					, alParamsCoupleSql.ToArray()
					);
				dsGetData.Tables[0].TableName = "Sys_Partner";
				DataUtils.MoveDataTable(ref mdsFinal, ref dsGetData);
				#endregion

				// Return Good:
				TDALUtils.DBUtils.CommitSafety(_dbCarSv);
				mdsFinal.AcceptChanges();
				return mdsFinal;
			}
			catch (Exception exc)
			{
				#region // Catch of try:
				// Rollback:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);

				// Return Bad:
				return TUtils.CProcessException.Process(
					ref mdsFinal
					, exc
					, strErrorCodeDefault
					, alParamsCoupleError.ToArray()
					);
				#endregion
			}
			finally
			{
				#region // Finally of try:
				// Rollback and Release resources:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);
				TDALUtils.DBUtils.ReleaseAllSemaphore(_dbCarSv_Sys, true);

				TUtils.CProcessException.Process(
					ref mdsFinal // mdsFinal
					, _log // log
					, strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strFunctionName // strFunctionName
					, TUtils.CUtils.TidNext(strTid, ref nTidSeq) // strAppTid
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, strLanguageCode // strLanguageCode
					, "" // strRemark
					);
				#endregion
			}
		}
		public DataSet Ser_SysGetObjectType(
			string strGWUserCode
			, string strGWPassword
			, string strTid
			, string strPartnerCode
			, string strPartnerUserCode
			, string strLanguageCode
			, string strObjectTypeList
			, string strDealerCodeList
			)
		{
			#region // Temp:
			DataSet mdsFinal = CMyDataSet.NewMyDataSet(strTid);
			int nTidSeq = 0;
			bool bNeedTransaction = false;
			string strFunctionName = "Ser_SysGetObjectType";
			string strErrorCodeDefault = TError.ErrITS.Ser_SysGetObjectType;
			ArrayList alParamsCoupleError = new ArrayList(new object[]{
					"strFunctionName", strFunctionName
					, "strObjectTypeList", strObjectTypeList
					});
			#endregion

			try
			{
				#region // Init:
				_dbCarSv.AppUserID = strPartnerUserCode;
				if (bNeedTransaction) _dbCarSv.BeginTransaction();

				// Write request log:
				_log.WriteLogAsync(
					strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strTid // strAppTid
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, TError.Error.NoError // strAppErrorCode
					, strFunctionName // strAppLogType1
					, "REQUEST" // strAppLogType2
					, "" // strAppLogType3
					, strLanguageCode // strAppLanguageCode
					, "" // strAppRemark
					, TUtils.CUtils.ParamsCouple2ParamsTriple(alParamsCoupleError, 1, "").ToArray() // arrobjParamsTriple
					);

				// Check Valid Tid:
				myUtils_ValidateId(
					ref alParamsCoupleError // alParamsCoupleError
					, strTid // strTid
					, TError.ErrITS.CommonInvalidTid // strErrCodeWhenInvalid
					);
				#endregion

				#region // Build Sql:
				ArrayList alParamsCoupleSql = new ArrayList();
				string strSqlGetData = @"
						select
							t.ObjectType
							, t.ObjectTypeName
						from Sys_ObjectType t with (nolock)
						where (1=1)
							zzzzClauseWhereObjectTypeList
						;
					";
				string zzzzClauseWhereObjectTypeList = SqlUtils.BuildClauseConditionList("and", "t.ObjectType", strObjectTypeList, "|");
				strSqlGetData = StringUtils.Replace(
					strSqlGetData
					, "zzzzClauseWhereObjectTypeList", zzzzClauseWhereObjectTypeList
					);
				#endregion

				#region // Get Data:
				myDebug_SaveSql(
					_bDebugMode // bDebugMode
					, ref alParamsCoupleError // alParamsCoupleError
					, string.Format("strSql_{0}", strFunctionName) // strParamName
					, strSqlGetData // strSql
					);
				DataSet dsGetData = _dbCarSv.ExecQuery(
					strSqlGetData
					, alParamsCoupleSql.ToArray()
					);
				dsGetData.Tables[0].TableName = "Sys_ObjectType";
				DataUtils.MoveDataTable(ref mdsFinal, ref dsGetData);
				#endregion

				// Return Good:
				TDALUtils.DBUtils.CommitSafety(_dbCarSv);
				mdsFinal.AcceptChanges();
				return mdsFinal;
			}
			catch (Exception exc)
			{
				#region // Catch of try:
				// Rollback:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);

				// Return Bad:
				return TUtils.CProcessException.Process(
					ref mdsFinal
					, exc
					, strErrorCodeDefault
					, alParamsCoupleError.ToArray()
					);
				#endregion
			}
			finally
			{
				#region // Finally of try:
				// Rollback and Release resources:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);
				TDALUtils.DBUtils.ReleaseAllSemaphore(_dbCarSv_Sys, true);

				TUtils.CProcessException.Process(
					ref mdsFinal // mdsFinal
					, _log // log
					, strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strFunctionName // strFunctionName
					, TUtils.CUtils.TidNext(strTid, ref nTidSeq) // strAppTid
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, strLanguageCode // strLanguageCode
					, "" // strRemark
					);
				#endregion
			}
		}
		public DataSet Ser_SysGetObject(
			string strGWUserCode
			, string strGWPassword
			, string strTid
			, string strPartnerCode
			, string strPartnerUserCode
			, string strLanguageCode
			, string strPartnerCodeList
			, string strObjectCodeList
			, string strFlagActiveList
			)
		{
			#region // Temp:
			DataSet mdsFinal = CMyDataSet.NewMyDataSet(strTid);
			int nTidSeq = 0;
			bool bNeedTransaction = false;
			string strFunctionName = "Ser_SysGetObject";
			string strErrorCodeDefault = TError.ErrITS.Ser_SysGetObject;
			ArrayList alParamsCoupleError = new ArrayList(new object[]{
					"strFunctionName", strFunctionName
					, "strPartnerCodeList", strPartnerCodeList
					, "strObjectCodeList", strObjectCodeList
					, "strFlagActiveList", strFlagActiveList
					});
			#endregion

			try
			{
				#region // Init:
				_dbCarSv.AppUserID = strPartnerUserCode;
				if (bNeedTransaction) _dbCarSv.BeginTransaction();

				// Write request log:
				_log.WriteLogAsync(
					strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strTid // strAppTid
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, TError.Error.NoError // strAppErrorCode
					, strFunctionName // strAppLogType1
					, "REQUEST" // strAppLogType2
					, "" // strAppLogType3
					, strLanguageCode // strAppLanguageCode
					, "" // strAppRemark
					, TUtils.CUtils.ParamsCouple2ParamsTriple(alParamsCoupleError, 1, "").ToArray() // arrobjParamsTriple
					);

				// Check Valid Tid:
				myUtils_ValidateId(
					ref alParamsCoupleError // alParamsCoupleError
					, strTid // strTid
					, TError.ErrITS.CommonInvalidTid // strErrCodeWhenInvalid
					);
				#endregion

				#region // Build Sql:
				ArrayList alParamsCoupleSql = new ArrayList();
				string strSqlGetData = StringUtils.Replace(@"
						select
							zzzzClauseColumnForSysObjectInfo
						from Sys_Object t with (nolock)
							--inner join Sys_ObjectType sot
								--on t.ObjectType = sot.ObjectType
							--inner join Sys_Partner sp
								--on t.PartnerCode = sp.PartnerCode
						where (1=1)
							zzzzClauseWherePartnerCodeList
							zzzzClauseWhereObjectCodeList
							zzzzClauseWhereFlagActiveList
						;
					"
					, "zzzzClauseColumnForSysObjectInfo", mySql_GetClauseColumnForSysObjectInfo("t.")
					);
				string zzzzClauseWherePartnerCodeList = SqlUtils.BuildClauseConditionList("and", "t.PartnerCode", strPartnerCodeList, "|");
				string zzzzClauseWhereObjectCodeList = SqlUtils.BuildClauseConditionList("and", "t.ObjectCode", strObjectCodeList, "|");
                //string zzzzClauseWhereObjectTypeList = SqlUtils.BuildClauseConditionList("and", "t.ObjectType", strObjectTypeList, "|");
				string zzzzClauseWhereFlagActiveList = SqlUtils.BuildClauseConditionList("and", "t.FlagActive", strFlagActiveList, "|");
                //string zzzzClauseWhereDealerCodeList = SqlUtils.BuildClauseConditionList("and", "t.DealerCode", strDealerCodeList, "|");
				strSqlGetData = StringUtils.Replace(
					strSqlGetData
					, "zzzzClauseWherePartnerCodeList", zzzzClauseWherePartnerCodeList
					, "zzzzClauseWhereObjectCodeList", zzzzClauseWhereObjectCodeList
					, "zzzzClauseWhereFlagActiveList", zzzzClauseWhereFlagActiveList
					);
				#endregion

				#region // Get Data:
				myDebug_SaveSql(
					_bDebugMode // bDebugMode
					, ref alParamsCoupleError // alParamsCoupleError
					, string.Format("strSql_{0}", strFunctionName) // strParamName
					, strSqlGetData // strSql
					);
				DataSet dsGetData = _dbCarSv.ExecQuery(
					strSqlGetData
					, alParamsCoupleSql.ToArray()
					);
				dsGetData.Tables[0].TableName = "Sys_Object";
				DataUtils.MoveDataTable(ref mdsFinal, ref dsGetData);
				#endregion

				// Return Good:
				TDALUtils.DBUtils.CommitSafety(_dbCarSv);
				mdsFinal.AcceptChanges();
				return mdsFinal;
			}
			catch (Exception exc)
			{
				#region // Catch of try:
				// Rollback:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);

				// Return Bad:
				return TUtils.CProcessException.Process(
					ref mdsFinal
					, exc
					, strErrorCodeDefault
					, alParamsCoupleError.ToArray()
					);
				#endregion
			}
			finally
			{
				#region // Finally of try:
				// Rollback and Release resources:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);
				TDALUtils.DBUtils.ReleaseAllSemaphore(_dbCarSv_Sys, true);

				TUtils.CProcessException.Process(
					ref mdsFinal // mdsFinal
					, _log // log
					, strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strFunctionName // strFunctionName
					, TUtils.CUtils.TidNext(strTid, ref nTidSeq) // strAppTid
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, strLanguageCode // strLanguageCode
					, "" // strRemark
					);
				#endregion
			}
		}

		public DataSet Ser_SysGetMapSysGroupSysObject(
			string strGWUserCode
			, string strGWPassword
			, string strTid
			, string strPartnerCode
			, string strPartnerUserCode
			, string strLanguageCode
			, string strGroupCodeList
			, string strPartnerCodeList
			, string strObjectCodeList
			, string strObjectTypeList
			, string strFlagActiveListForObject
			)
		{
			#region // Temp:
			DataSet mdsFinal = CMyDataSet.NewMyDataSet(strTid);
			int nTidSeq = 0;
			bool bNeedTransaction = false;
			string strFunctionName = "Ser_SysGetMapSysGroupSysObject";
			string strErrorCodeDefault = TError.ErrITS.Ser_SysGetMapSysGroupSysObject;
			ArrayList alParamsCoupleError = new ArrayList(new object[]{
					"strFunctionName", strFunctionName
					, "strGroupCodeList", strGroupCodeList
					, "strPartnerCodeList", strPartnerCodeList
					, "strObjectCodeList", strObjectCodeList
                    , "strObjectTypeList", strObjectTypeList
                    , "strFlagActiveListForObject", strFlagActiveListForObject
                    //, "strDealerCode", strDealerCodeList
					});
			#endregion

			try
			{
				#region // Init:
				_dbCarSv.AppUserID = strPartnerUserCode;
				if (bNeedTransaction) _dbCarSv.BeginTransaction();

				// Write request log:
				_log.WriteLogAsync(
					strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strTid // strAppTid
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, TError.Error.NoError // strAppErrorCode
					, strFunctionName // strAppLogType1
					, "REQUEST" // strAppLogType2
					, "" // strAppLogType3
					, strLanguageCode // strAppLanguageCode
					, "" // strAppRemark
					, TUtils.CUtils.ParamsCouple2ParamsTriple(alParamsCoupleError, 1, "").ToArray() // arrobjParamsTriple
					);

				// Check Valid Tid:
				myUtils_ValidateId(
					ref alParamsCoupleError // alParamsCoupleError
					, strTid // strTid
					, TError.ErrITS.CommonInvalidTid // strErrCodeWhenInvalid
					);
				#endregion

				#region // Build Sql:
				ArrayList alParamsCoupleSql = new ArrayList();
				string strSqlGetData = StringUtils.Replace(@"
						select
							sg.GroupCode
							, sg.GroupName
							, zzzzClauseColumnForSysObjectInfo
						from Sys_MapGroupObject t with (nolock)
							inner join Sys_Group sg
								on t.GroupCode = sg.GroupCode
							inner join Sys_Object so
								on t.ObjectCode = so.ObjectCode --and t.PartnerCode = so.PartnerCode
						where (1=1)
							zzzzClauseWhereGroupCodeList
							zzzzClauseWherePartnerCodeList
							zzzzClauseWhereObjectCodeList
                            zzzzClauseWhereObjectTypeList
                            zzzzClauseWhereFlagActiveListForObject
							
						;
					"
                    , "zzzzClauseColumnForSysObjectInfo", mySql_GetClauseColumnForSysObjectInfo("so.")
					);
				string zzzzClauseWhereGroupCodeList = SqlUtils.BuildClauseConditionList("and", "t.GroupCode", strGroupCodeList, "|");
				string zzzzClauseWherePartnerCodeList = SqlUtils.BuildClauseConditionList("and", "t.PartnerCode", strPartnerCodeList, "|");
				string zzzzClauseWhereObjectCodeList = SqlUtils.BuildClauseConditionList("and", "t.ObjectCode", strObjectCodeList, "|");
				string zzzzClauseWhereObjectTypeList = SqlUtils.BuildClauseConditionList("and", "so.ObjectType", strObjectTypeList, "|");
				string zzzzClauseWhereFlagActiveListForObject = SqlUtils.BuildClauseConditionList("and", "so.FlagActive", strFlagActiveListForObject, "|");
                //string zzzzClauseWhereDealerCodeList = SqlUtils.BuildClauseConditionList("and", "sg.DealerCode", strDealerCodeList, "|");
				strSqlGetData = StringUtils.Replace(
					strSqlGetData
					, "zzzzClauseWhereGroupCodeList", zzzzClauseWhereGroupCodeList
					, "zzzzClauseWherePartnerCodeList", zzzzClauseWherePartnerCodeList
					, "zzzzClauseWhereObjectCodeList", zzzzClauseWhereObjectCodeList
					, "zzzzClauseWhereObjectTypeList", zzzzClauseWhereObjectTypeList
					, "zzzzClauseWhereFlagActiveListForObject", zzzzClauseWhereFlagActiveListForObject
                    //, "zzzzClauseWhereDealerCodeList", zzzzClauseWhereDealerCodeList
					);
				#endregion

				#region // Get Data:
				myDebug_SaveSql(
					_bDebugMode // bDebugMode
					, ref alParamsCoupleError // alParamsCoupleError
					, string.Format("strSql_{0}", strFunctionName) // strParamName
					, strSqlGetData // strSql
					);
				DataSet dsGetData = _dbCarSv.ExecQuery(
					strSqlGetData
					, alParamsCoupleSql.ToArray()
					);
				dsGetData.Tables[0].TableName = "Map_SG_SO";
				DataUtils.MoveDataTable(ref mdsFinal, ref dsGetData);
				#endregion

				// Return Good:
				TDALUtils.DBUtils.CommitSafety(_dbCarSv);
				mdsFinal.AcceptChanges();
				return mdsFinal;
			}
			catch (Exception exc)
			{
				#region // Catch of try:
				// Rollback:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);

				// Return Bad:
				return TUtils.CProcessException.Process(
					ref mdsFinal
					, exc
					, strErrorCodeDefault
					, alParamsCoupleError.ToArray()
					);
				#endregion
			}
			finally
			{
				#region // Finally of try:
				// Rollback and Release resources:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);
				TDALUtils.DBUtils.ReleaseAllSemaphore(_dbCarSv_Sys, true);

				TUtils.CProcessException.Process(
					ref mdsFinal // mdsFinal
					, _log // log
					, strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strFunctionName // strFunctionName
					, TUtils.CUtils.TidNext(strTid, ref nTidSeq) // strAppTid
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, strLanguageCode // strLanguageCode
					, "" // strRemark
					);
				#endregion
			}
		}
		public DataSet Ser_SysGetMapSysUserSysObjectForCurrentUser(
			string strGWUserCode
			, string strGWPassword
			, string strTid
			, string strPartnerCode
			, string strPartnerUserCode
			, string strLanguageCode
			)
		{
			#region // Temp:
			DataSet mdsFinal = CMyDataSet.NewMyDataSet(strTid);
			int nTidSeq = 0;
			bool bNeedTransaction = false;
			string strFunctionName = "Ser_SysGetMapSysUserSysObjectForCurrentUser";
			string strErrorCodeDefault = TError.ErrITS.Ser_SysGetMapSysUserSysObjectForCurrentUser;
			ArrayList alParamsCoupleError = new ArrayList(new object[]{
					"strFunctionName", strFunctionName
					});
			#endregion

			try
			{
				#region // Init:
				_dbCarSv.AppUserID = strPartnerUserCode;
				if (bNeedTransaction) _dbCarSv.BeginTransaction();

				// Write request log:
				_log.WriteLogAsync(
					strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strTid // strAppTid
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, TError.Error.NoError // strAppErrorCode
					, strFunctionName // strAppLogType1
					, "REQUEST" // strAppLogType2
					, "" // strAppLogType3
					, strLanguageCode // strAppLanguageCode
					, "" // strAppRemark
					, TUtils.CUtils.ParamsCouple2ParamsTriple(alParamsCoupleError, 1, "").ToArray() // arrobjParamsTriple
					);

				// Check Valid Tid:
				myUtils_ValidateId(
					ref alParamsCoupleError // alParamsCoupleError
					, strTid // strTid
					, TError.ErrITS.CommonInvalidTid // strErrCodeWhenInvalid
					);
				#endregion

				#region // Get Data:
				DataTable dt_Map_SU_SO = null;
				mySys_GetMapSysUserSysObject(
					ref alParamsCoupleError // alParamsCoupleError
					, strPartnerUserCode // strUserCodeList
					, "" // strUserNamePattern
					, TConst.Flag.Active // strFlagActiveListForUser
					, "" // strBUCodeList
					, "" // strBUCodePattern
					, TConst.Flag.Active // strFlagActiveListForDealer
					, "" // strGroupCodeList
					, strPartnerCode // strPartnerCodeList
					, "" // strObjectCodeList
					, "" // strObjectTypeList
					, TConst.Flag.Active // strFlagActiveListForObject
					, out dt_Map_SU_SO // dt_Map_SU_SO
					);
				DataUtils.MoveDataTable(ref mdsFinal, ref dt_Map_SU_SO);
				#endregion

				// Return Good:
				TDALUtils.DBUtils.CommitSafety(_dbCarSv);
				mdsFinal.AcceptChanges();
				return mdsFinal;
			}
			catch (Exception exc)
			{
				#region // Catch of try:
				// Rollback:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);

				// Return Bad:
				return TUtils.CProcessException.Process(
					ref mdsFinal
					, exc
					, strErrorCodeDefault
					, alParamsCoupleError.ToArray()
					);
				#endregion
			}
			finally
			{
				#region // Finally of try:
				// Rollback and Release resources:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);
				TDALUtils.DBUtils.ReleaseAllSemaphore(_dbCarSv_Sys, true);

				TUtils.CProcessException.Process(
					ref mdsFinal // mdsFinal
					, _log // log
					, strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strFunctionName // strFunctionName
					, TUtils.CUtils.TidNext(strTid, ref nTidSeq) // strAppTid
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, strLanguageCode // strLanguageCode
					, "" // strRemark
					);
				#endregion
			}
		}
		public DataSet Ser_SysGetMapSysUserSysObject(
			string strGWUserCode
			, string strGWPassword
			, string strTid
			, string strPartnerCode
			, string strPartnerUserCode
			, string strLanguageCode
			, string strUserCodeList
			, string strUserNamePattern
			, string strFlagActiveListForUser
			, string strBUCodeList
			, string strBUCodePattern
			, string strFlagActiveListForDealer
			, string strGroupCodeList
			, string strPartnerCodeList
			, string strObjectCodeList
			, string strObjectTypeList
			, string strFlagActiveListForObject
			)
		{
			#region // Temp:
			DataSet mdsFinal = CMyDataSet.NewMyDataSet(strTid);
			int nTidSeq = 0;
			bool bNeedTransaction = false;
			string strFunctionName = "Ser_SysGetMapSysUserSysObject";
			string strErrorCodeDefault = TError.ErrITS.Ser_SysGetMapSysUserSysObject;
			ArrayList alParamsCoupleError = new ArrayList(new object[]{
					"strFunctionName", strFunctionName
					, "strUserCodeList", strUserCodeList
					, "strUserNamePattern", strUserNamePattern
					, "strFlagActiveListForUser", strFlagActiveListForUser
					, "strBUCodeList", strBUCodeList
					, "strBUCodePattern", strBUCodePattern
					, "strFlagActiveListForDealer", strFlagActiveListForDealer
					, "strGroupCodeList", strGroupCodeList
					, "strPartnerCodeList", strPartnerCodeList
					, "strObjectCodeList", strObjectCodeList
					, "strObjectTypeList", strObjectTypeList
					, "strFlagActiveListForObject", strFlagActiveListForObject
					});
			#endregion

			try
			{
				#region // Init:
				_dbCarSv.AppUserID = strPartnerUserCode;
				if (bNeedTransaction) _dbCarSv.BeginTransaction();

				// Write request log:
				_log.WriteLogAsync(
					strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strTid // strAppTid
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, TError.Error.NoError // strAppErrorCode
					, strFunctionName // strAppLogType1
					, "REQUEST" // strAppLogType2
					, "" // strAppLogType3
					, strLanguageCode // strAppLanguageCode
					, "" // strAppRemark
					, TUtils.CUtils.ParamsCouple2ParamsTriple(alParamsCoupleError, 1, "").ToArray() // arrobjParamsTriple
					);

				// Check Valid Tid:
				myUtils_ValidateId(
					ref alParamsCoupleError // alParamsCoupleError
					, strTid // strTid
					, TError.ErrITS.CommonInvalidTid // strErrCodeWhenInvalid
					);
				#endregion

				#region // Get Data:
				DataTable dt_Map_SU_SO = null;
				mySys_GetMapSysUserSysObject(
					ref alParamsCoupleError // alParamsCoupleError
					, strUserCodeList // strUserCodeList

					, strUserNamePattern // strUserNamePattern

					, strFlagActiveListForUser // strFlagActiveListForUser
					, strBUCodeList // strBUCodeList
					, strBUCodePattern // strBUCodePattern
					, strFlagActiveListForDealer // strFlagActiveListForDealer
					, strGroupCodeList // strGroupCodeList
					, strPartnerCodeList // strPartnerCodeList
					, strObjectCodeList // strObjectCodeList
					, strObjectTypeList // strObjectTypeList
					, strFlagActiveListForObject // strFlagActiveListForObject
					, out dt_Map_SU_SO // dt_Map_SU_SO
					);
				DataUtils.MoveDataTable(ref mdsFinal, ref dt_Map_SU_SO);
				#endregion

				// Return Good:
				TDALUtils.DBUtils.CommitSafety(_dbCarSv);
				mdsFinal.AcceptChanges();
				return mdsFinal;
			}
			catch (Exception exc)
			{
				#region // Catch of try:
				// Rollback:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);

				// Return Bad:
				return TUtils.CProcessException.Process(
					ref mdsFinal
					, exc
					, strErrorCodeDefault
					, alParamsCoupleError.ToArray()
					);
				#endregion
			}
			finally
			{
				#region // Finally of try:
				// Rollback and Release resources:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);
				TDALUtils.DBUtils.ReleaseAllSemaphore(_dbCarSv_Sys, true);

				TUtils.CProcessException.Process(
					ref mdsFinal // mdsFinal
					, _log // log
					, strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strFunctionName // strFunctionName
					, TUtils.CUtils.TidNext(strTid, ref nTidSeq) // strAppTid
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, strLanguageCode // strLanguageCode
					, "" // strRemark
					);
				#endregion
			}
		}
		public DataSet Ser_SysResetUserPassword(
			string strGWUserCode
			, string strGWPassword
			, string strTid
			, string strPartnerCode
			, string strPartnerUserCode
			, string strLanguageCode
			, string strUserCodeReset
			, string strPasswordReset
			)
		{
			#region // Temp:
			DataSet mdsFinal = CMyDataSet.NewMyDataSet(strTid);
			int nTidSeq = 0;
			bool bNeedTransaction = true;
			string strFunctionName = "Ser_SysResetUserPassword";
			string strErrorCodeDefault = TError.ErrITS.Ser_SysResetUserPassword;
			ArrayList alParamsCoupleError = new ArrayList(new object[]{
					"strFunctionName", strFunctionName
					, "strUserCode", strUserCodeReset
					});
			#endregion

			try
			{
				#region // Init:
				_dbCarSv.AppUserID = strPartnerUserCode;
				if (bNeedTransaction) _dbCarSv.BeginTransaction();

				// Write request log:
				_log.WriteLogAsync(
					strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strTid // strAppTid
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, TError.Error.NoError // strAppErrorCode
					, strFunctionName // strAppLogType1
					, "REQUEST" // strAppLogType2
					, "" // strAppLogType3
					, strLanguageCode // strAppLanguageCode
					, "" // strAppRemark
					, TUtils.CUtils.ParamsCouple2ParamsTriple(alParamsCoupleError, 1, "").ToArray() // arrobjParamsTriple
					);

				// Check Valid Tid:
				myUtils_ValidateId(
					ref alParamsCoupleError // alParamsCoupleError
					, strTid // strTid
					, TError.ErrITS.CommonInvalidTid // strErrCodeWhenInvalid
					);
				#endregion

				#region // Check:
				// Refine:
				strUserCodeReset = strUserCodeReset.ToUpper();

				// CheckUserExist:
				DataTable dt_Sys_User = null;
				mySys_CheckUser(
					ref alParamsCoupleError // alParamsCoupleError
					, strUserCodeReset // strUserCode
					, TConst.Flag.Active // strFlagExistToCheck
					, TConst.Flag.Active // strFlagActiveListToCheck
					, out dt_Sys_User
					);
				#endregion

				#region // dt_Sys_User:
				ArrayList alColumnEffective = new ArrayList();
				dt_Sys_User.Rows[0]["UserPassword"] = strPasswordReset; alColumnEffective.Add("UserPassword");
				_dbCarSv.SaveData("Sys_User", dt_Sys_User, alColumnEffective.ToArray());
				#endregion

				// Return Good:
				TDALUtils.DBUtils.CommitSafety(_dbCarSv);
				mdsFinal.AcceptChanges();
				return mdsFinal;
			}
			catch (Exception exc)
			{
				#region // Catch of try:
				// Rollback:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);

				// Return Bad:
				return TUtils.CProcessException.Process(
					ref mdsFinal
					, exc
					, strErrorCodeDefault
					, alParamsCoupleError.ToArray()
					);
				#endregion
			}
			finally
			{
				#region // Finally of try:
				// Rollback and Release resources:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);
				TDALUtils.DBUtils.ReleaseAllSemaphore(_dbCarSv_Sys, true);

				TUtils.CProcessException.Process(
					ref mdsFinal // mdsFinal
					, _log // log
					, strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strFunctionName // strFunctionName
					, TUtils.CUtils.TidNext(strTid, ref nTidSeq) // strAppTid
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, strLanguageCode // strLanguageCode
					, "" // strRemark
					);
				#endregion
			}
		}
		public DataSet Ser_SysSaveUser(
			string strGWUserCode
			, string strGWPassword
			, string strTid
			, string strPartnerCode
			, string strPartnerUserCode
			, string strLanguageCode
			, DataSet ds_Sys_User
			)
		{
			#region // Temp:
			DataSet mdsFinal = CMyDataSet.NewMyDataSet(strTid);
			int nTidSeq = 0;
			bool bNeedTransaction = true;
			string strFunctionName = "Ser_SysSaveUser";
			string strErrorCodeDefault = TError.ErrITS.Ser_SysSaveUser;
			ArrayList alParamsCoupleError = new ArrayList(new object[]{
					"strFunctionName", strFunctionName
					, "ds_Sys_User", XmlUtils.DataSet2Xml(ds_Sys_User, XmlWriteMode.IgnoreSchema)
					});
			#endregion

			try
			{
				#region // Init:
				_dbCarSv.AppUserID = strPartnerUserCode;
				if (bNeedTransaction) _dbCarSv.BeginTransaction();

				// Write request log:
				_log.WriteLogAsync(
					strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strTid // strAppTid
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, TError.Error.NoError // strAppErrorCode
					, strFunctionName // strAppLogType1
					, "REQUEST" // strAppLogType2
					, "" // strAppLogType3
					, strLanguageCode // strAppLanguageCode
					, "" // strAppRemark
					, TUtils.CUtils.ParamsCouple2ParamsTriple(alParamsCoupleError, 1, "").ToArray() // arrobjParamsTriple
					);

				// Check Valid Tid:
				myUtils_ValidateId(
					ref alParamsCoupleError // alParamsCoupleError
					, strTid // strTid
					, TError.ErrITS.CommonInvalidTid // strErrCodeWhenInvalid
					);
				#endregion

				#region // Check:
				// dt_Sys_User:
				if (!ds_Sys_User.Tables.Contains("Sys_User"))
				{
					throw CMyException.Raise(
						TError.ErrITS.SysSaveUser_TableNotFound
						, null
						, alParamsCoupleError.ToArray()
						);
				}
				DataTable dt_Sys_User = ds_Sys_User.Tables["Sys_User"];
				#endregion

				#region // dt_Sys_User:
				// Init:
				ArrayList alColumnEffectiveForNotChangePassword = new ArrayList();
				alColumnEffectiveForNotChangePassword.Add("UserCode");
				alColumnEffectiveForNotChangePassword.Add("UserName");
				alColumnEffectiveForNotChangePassword.Add("FlagActive");
				ArrayList alColumnEffectiveForChangePassword = new ArrayList(alColumnEffectiveForNotChangePassword);
				alColumnEffectiveForChangePassword.Add("UserPassword");

				// Process Deleted:
				DataTable dtDeleted = dt_Sys_User.GetChanges(DataRowState.Deleted);
				if (dtDeleted != null)
				{
					_dbCarSv.SaveData("Sys_User", dtDeleted);
				}

				// Process Modified:
				DataTable dtModified = dt_Sys_User.GetChanges(DataRowState.Modified);
				if (dtModified != null)
				{
					// Init:
					DataTable dtUserChangePassword = dtModified.Clone(); // Structure only.
                    DataTable dtUserNotChangePassword = dtModified.Clone(); // Structure only.
                    for (int i = 0; i < dtModified.Rows.Count; i++)
					{
						if (StringUtils.StringEqual(dtModified.Rows[i]["UserPassword"], TConst.HTCConst.PasswordTemplate))
						{
							dtUserNotChangePassword.Rows.Add(dtModified.Rows[i].ItemArray);
						}
						else
						{
							dtUserChangePassword.Rows.Add(dtModified.Rows[i].ItemArray);
						}
					}

					// dtUserNotChangePassword:
					DataUtils.ResetAllDataRowState(ref dtUserNotChangePassword, DataRowState.Modified);
					DataUtils.StandardizeValuesOfColumns(ref dtUserNotChangePassword, "UserCode");
					_dbCarSv.SaveData("Sys_User", dtUserNotChangePassword, alColumnEffectiveForNotChangePassword.ToArray());

					// dtUserChangePassword:
					DataUtils.ResetAllDataRowState(ref dtUserChangePassword, DataRowState.Modified);
					DataUtils.StandardizeValuesOfColumns(ref dtUserChangePassword, "UserCode");
					_dbCarSv.SaveData("Sys_User", dtUserChangePassword, alColumnEffectiveForChangePassword.ToArray());
				}

				// Process Added:
				DataTable dtAdded = dt_Sys_User.GetChanges(DataRowState.Added);
				DataUtils.StandardizeValuesOfColumns(ref dtAdded, "UserCode");
				if (dtAdded != null)
				{
					_dbCarSv.SaveData("Sys_User", dtAdded, alColumnEffectiveForChangePassword.ToArray());
				}
				#endregion

				// Return Good:
				TDALUtils.DBUtils.CommitSafety(_dbCarSv);
				mdsFinal.AcceptChanges();
				return mdsFinal;
			}
			catch (Exception exc)
			{
				#region // Catch of try:
				// Rollback:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);

				// Return Bad:
				return TUtils.CProcessException.Process(
					ref mdsFinal
					, exc
					, strErrorCodeDefault
					, alParamsCoupleError.ToArray()
					);
				#endregion
			}
			finally
			{
				#region // Finally of try:
				// Rollback and Release resources:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);
				TDALUtils.DBUtils.ReleaseAllSemaphore(_dbCarSv_Sys, true);

				TUtils.CProcessException.Process(
					ref mdsFinal // mdsFinal
					, _log // log
					, strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strFunctionName // strFunctionName
					, TUtils.CUtils.TidNext(strTid, ref nTidSeq) // strAppTid
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, strLanguageCode // strLanguageCode
					, "" // strRemark
					);
				#endregion
			}
		}
		public DataSet Ser_SysSaveGroup(
			string strGWUserCode
			, string strGWPassword
			, string strTid
			, string strPartnerCode
			, string strPartnerUserCode
			, string strLanguageCode
            , string strGroupCodeListForDelete
			, DataSet ds_Sys_Group
			)
		{
			#region // Temp:
			DataSet mdsFinal = CMyDataSet.NewMyDataSet(strTid);
			int nTidSeq = 0;
			bool bNeedTransaction = true;
			string strFunctionName = "Ser_SysSaveGroup";
			string strErrorCodeDefault = TError.ErrITS.Ser_SysSaveGroup;
			ArrayList alParamsCoupleError = new ArrayList(new object[]{
					"strFunctionName", strFunctionName
					, "ds_Sys_Group", XmlUtils.DataSet2Xml(ds_Sys_Group, XmlWriteMode.IgnoreSchema)
					});
			#endregion

			try
			{
				#region // Init:
				_dbCarSv.AppUserID = strPartnerUserCode;
				if (bNeedTransaction) _dbCarSv.BeginTransaction();

				// Write request log:
				_log.WriteLogAsync(
					strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strTid // strAppTid
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, TError.Error.NoError // strAppErrorCode
					, strFunctionName // strAppLogType1
					, "REQUEST" // strAppLogType2
					, "" // strAppLogType3
					, strLanguageCode // strAppLanguageCode
					, "" // strAppRemark
					, TUtils.CUtils.ParamsCouple2ParamsTriple(alParamsCoupleError, 1, "").ToArray() // arrobjParamsTriple
					);

				// Check Valid Tid:
				myUtils_ValidateId(
					ref alParamsCoupleError // alParamsCoupleError
					, strTid // strTid
					, TError.ErrITS.CommonInvalidTid // strErrCodeWhenInvalid
					);
				#endregion

				#region // Check:
				// dt_Sys_Group:
				if (!ds_Sys_Group.Tables.Contains("Sys_Group"))
				{
					throw CMyException.Raise(
						TError.ErrITS.SysSaveGroup_TableNotFound
						, null
						, alParamsCoupleError.ToArray()
						);
                }
                #region //Clear all
                // strGroupCodeList:
                string zzzzClauseWhere_strGroupCodeList = SqlUtils.BuildClauseConditionList("and", "t.GroupCode", strGroupCodeListForDelete, "|");               

                    if (!StringUtils.IsEmpty(strGroupCodeListForDelete))
                    {
                        #region //Delete from Map_SG_SU
                        string strSqlDelete = StringUtils.Replace(@"
						delete t
						from Sys_MapUserGroup t
						where (1=1)
							zzzzClauseWhere_strGroupCodeList
					"
                 , "zzzzClauseWhere_strGroupCodeList", zzzzClauseWhere_strGroupCodeList
                 );
                        myDebug_SaveSql(
                            _bDebugMode // bDebugMode
                            , ref alParamsCoupleError // alParamsCoupleError
                            , string.Format("strSql_{0}_Clear", strFunctionName) // strParamName
                            , strSqlDelete // strSql
                            );
                        _dbCarSv.ExecQuery(strSqlDelete);
                        #endregion //Delete from Map_SG_SU

                        #region //Delete from Map_SG_SU
                        string strSqlDelete_SO = StringUtils.Replace(@"
						delete t
						from Sys_MapGroupObject t
						where (1=1)
							zzzzClauseWhere_strGroupCodeList
					"
             , "zzzzClauseWhere_strGroupCodeList", zzzzClauseWhere_strGroupCodeList
             );
                        myDebug_SaveSql(
                            _bDebugMode // bDebugMode
                            , ref alParamsCoupleError // alParamsCoupleError
                            , string.Format("strSql_{0}_Clear", strFunctionName) // strParamName
                            , strSqlDelete_SO // strSql
                            );
                        _dbCarSv.ExecQuery(strSqlDelete_SO);
                        #endregion //Delete from Map_SG_SU
                    }
                #endregion //Clear all


                DataTable dt_Sys_Group = ds_Sys_Group.Tables["Sys_Group"].GetChanges();
                DataUtils.StandardizeValuesOfColumns(ref dt_Sys_Group, "GroupCode");
				#endregion

				#region // dt_Sys_Group:
				_dbCarSv.SaveData("Sys_Group", dt_Sys_Group);
				#endregion

				// Return Good:
				TDALUtils.DBUtils.CommitSafety(_dbCarSv);
				mdsFinal.AcceptChanges();
				return mdsFinal;
			}
			catch (Exception exc)
			{
				#region // Catch of try:
				// Rollback:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);

				// Return Bad:
				return TUtils.CProcessException.Process(
					ref mdsFinal
					, exc
					, strErrorCodeDefault
					, alParamsCoupleError.ToArray()
					);
				#endregion
			}
			finally
			{
				#region // Finally of try:
				// Rollback and Release resources:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);
				TDALUtils.DBUtils.ReleaseAllSemaphore(_dbCarSv_Sys, true);

				TUtils.CProcessException.Process(
					ref mdsFinal // mdsFinal
					, _log // log
					, strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strFunctionName // strFunctionName
					, TUtils.CUtils.TidNext(strTid, ref nTidSeq) // strAppTid
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, strLanguageCode // strLanguageCode
					, "" // strRemark
					);
				#endregion
			}
		}
		public DataSet Ser_SysSaveMapSysGroupSysUser(
			string strGWUserCode
			, string strGWPassword
			, string strTid
			, string strPartnerCode
			, string strPartnerUserCode
			, string strLanguageCode
			, string strGroupCodeList
            , DataSet ds_MapUserGroup
			)
		{
			#region // Temp:
			DataSet mdsFinal = CMyDataSet.NewMyDataSet(strTid);
			int nTidSeq = 0;
			bool bNeedTransaction = true;
			string strFunctionName = "Ser_SysSaveMapSysGroupSysUser";
			string strErrorCodeDefault = TError.ErrITS.Ser_SysSaveMapSysGroupSysUser;
			ArrayList alParamsCoupleError = new ArrayList(new object[]{
					"strFunctionName", strFunctionName
					, "strGroupCodeList", strGroupCodeList
					, "ds_MapUserGroup", XmlUtils.DataSet2Xml(ds_MapUserGroup, XmlWriteMode.IgnoreSchema)
					});
			#endregion

			try
			{
				#region // Init:
				_dbCarSv.AppUserID = strPartnerUserCode;
				if (bNeedTransaction) _dbCarSv.BeginTransaction();

				// Write request log:
				_log.WriteLogAsync(
					strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strTid // strAppTid
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, TError.Error.NoError // strAppErrorCode
					, strFunctionName // strAppLogType1
					, "REQUEST" // strAppLogType2
					, "" // strAppLogType3
					, strLanguageCode // strAppLanguageCode
					, "" // strAppRemark
					, TUtils.CUtils.ParamsCouple2ParamsTriple(alParamsCoupleError, 1, "").ToArray() // arrobjParamsTriple
					);

				// Check Valid Tid:
				myUtils_ValidateId(
					ref alParamsCoupleError // alParamsCoupleError
					, strTid // strTid
					, TError.ErrITS.CommonInvalidTid // strErrCodeWhenInvalid
					);
				#endregion

				#region // Check:
				// Refine:
				strGroupCodeList = strGroupCodeList.ToUpper();
				ds_MapUserGroup.AcceptChanges();

				// dt_Map_SG_SU:
                if (!ds_MapUserGroup.Tables.Contains("Sys_MapUserGroup"))
				{
					throw CMyException.Raise(
						TError.ErrITS.SysSaveMapSysGroupSysUser_TableNotFound
						, null
						, alParamsCoupleError.ToArray()
						);
				}
                DataTable dt_MapUserGroup = ds_MapUserGroup.Tables["Sys_MapUserGroup"];
                DataUtils.StandardizeValuesOfColumns(ref dt_MapUserGroup, "GroupCode", "UserCode");

				// strGroupCodeList:
				string zzzzClauseWhere_strGroupCodeList = SqlUtils.BuildClauseConditionList("and", "t.GroupCode", strGroupCodeList, "|");
				if (!zzzzClauseWhere_strGroupCodeList.StartsWith("and"))
				{
					throw CMyException.Raise(
						TError.ErrITS.SysSaveMapSysGroupSysUser_InvalidGroupCodeList
						, null
						, alParamsCoupleError.ToArray()
						);
				}
				#endregion

				#region // dt_Map_SG_SU:
				// Clear all:
				string strSqlDelete = StringUtils.Replace(@"
						delete t
						from Sys_MapUserGroup t
						where (1=1)
							zzzzClauseWhere_strGroupCodeList
					"
                    , "zzzzClauseWhere_strGroupCodeList", zzzzClauseWhere_strGroupCodeList
					);
				myDebug_SaveSql(
					_bDebugMode // bDebugMode
					, ref alParamsCoupleError // alParamsCoupleError
					, string.Format("strSql_{0}_Clear", strFunctionName) // strParamName
					, strSqlDelete // strSql
					);
				_dbCarSv.ExecQuery(strSqlDelete);

				// Insert all:
				DataUtils.ResetAllDataRowState(ref dt_MapUserGroup, DataRowState.Added);
                _dbCarSv.SaveData("Sys_MapUserGroup", dt_MapUserGroup);
				#endregion

				// Return Good:
				TDALUtils.DBUtils.CommitSafety(_dbCarSv);
				mdsFinal.AcceptChanges();
				return mdsFinal;
			}
			catch (Exception exc)
			{
				#region // Catch of try:
				// Rollback:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);

				// Return Bad:
				return TUtils.CProcessException.Process(
					ref mdsFinal
					, exc
					, strErrorCodeDefault
					, alParamsCoupleError.ToArray()
					);
				#endregion
			}
			finally
			{
				#region // Finally of try:
				// Rollback and Release resources:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);
				TDALUtils.DBUtils.ReleaseAllSemaphore(_dbCarSv_Sys, true);

				TUtils.CProcessException.Process(
					ref mdsFinal // mdsFinal
					, _log // log
					, strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strFunctionName // strFunctionName
					, TUtils.CUtils.TidNext(strTid, ref nTidSeq) // strAppTid
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, strLanguageCode // strLanguageCode
					, "" // strRemark
					);
				#endregion
			}
		}
		public DataSet Ser_SysSaveMapSysGroupSysObject(
			string strGWUserCode
			, string strGWPassword
			, string strTid
			, string strPartnerCode
			, string strPartnerUserCode
			, string strLanguageCode
			, string strGroupCodeList
			, DataSet ds_Map_SG_SO
			)
		{
			#region // Temp:
			DataSet mdsFinal = CMyDataSet.NewMyDataSet(strTid);
			int nTidSeq = 0;
			bool bNeedTransaction = true;
			string strFunctionName = "Ser_SysSaveMapSysGroupSysObject";
			string strErrorCodeDefault = TError.ErrITS.Ser_SysSaveMapSysGroupSysObject;
			ArrayList alParamsCoupleError = new ArrayList(new object[]{
					"strFunctionName", strFunctionName
					, "strGroupCodeList", strGroupCodeList
					, "ds_Map_SG_SO", XmlUtils.DataSet2Xml(ds_Map_SG_SO, XmlWriteMode.IgnoreSchema)
					});
			#endregion

			try
			{
				#region // Init:
				_dbCarSv.AppUserID = strPartnerUserCode;
				if (bNeedTransaction) _dbCarSv.BeginTransaction();

				// Write request log:
				_log.WriteLogAsync(
					strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strTid // strAppTid
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, TError.Error.NoError // strAppErrorCode
					, strFunctionName // strAppLogType1
					, "REQUEST" // strAppLogType2
					, "" // strAppLogType3
					, strLanguageCode // strAppLanguageCode
					, "" // strAppRemark
					, TUtils.CUtils.ParamsCouple2ParamsTriple(alParamsCoupleError, 1, "").ToArray() // arrobjParamsTriple
					);

				// Check Valid Tid:
				myUtils_ValidateId(
					ref alParamsCoupleError // alParamsCoupleError
					, strTid // strTid
					, TError.ErrITS.CommonInvalidTid // strErrCodeWhenInvalid
					);
				#endregion

				#region // Check:
				// Refine:
				strGroupCodeList = strGroupCodeList.ToUpper();
				ds_Map_SG_SO.AcceptChanges();

				// dt_Map_SG_SO:
                if (!ds_Map_SG_SO.Tables.Contains("Sys_MapGroupObject"))
				{
					throw CMyException.Raise(
						TError.ErrITS.SysSaveMapSysGroupSysObject_TableNotFound
						, null
						, alParamsCoupleError.ToArray()
						);
				}
                DataTable dt_Map_SG_SO = ds_Map_SG_SO.Tables["Sys_MapGroupObject"];
				DataUtils.StandardizeValuesOfColumns(ref dt_Map_SG_SO, "GroupCode", "PartnerCode", "ObjectCode");

				// strGroupCodeList:
				string zzzzClauseWhere_strGroupCodeList = SqlUtils.BuildClauseConditionList("and", "t.GroupCode", strGroupCodeList, "|");
				if (!zzzzClauseWhere_strGroupCodeList.StartsWith("and"))
				{
					throw CMyException.Raise(
						TError.ErrITS.SysSaveMapSysGroupSysUser_InvalidGroupCodeList
						, null
						, alParamsCoupleError.ToArray()
						);
				}
				#endregion

				#region // dt_Map_SG_SO:
				// Clear all:
				string strSqlDelete = StringUtils.Replace(@"
						delete t
						from Sys_MapGroupObject t
						where (1=1)
							zzzzClauseWhere_strGroupCodeList
					"
                    , "zzzzClauseWhere_strGroupCodeList", zzzzClauseWhere_strGroupCodeList
					);
				myDebug_SaveSql(
					_bDebugMode // bDebugMode
					, ref alParamsCoupleError // alParamsCoupleError
					, string.Format("strSql_{0}_Clear", strFunctionName) // strParamName
					, strSqlDelete // strSql
					);
				_dbCarSv.ExecQuery(strSqlDelete);

				// Insert all:
				DataUtils.ResetAllDataRowState(ref dt_Map_SG_SO, DataRowState.Added);
                _dbCarSv.SaveData("Sys_MapGroupObject", dt_Map_SG_SO);
				#endregion

				// Return Good:
				TDALUtils.DBUtils.CommitSafety(_dbCarSv);
				mdsFinal.AcceptChanges();
				return mdsFinal;
			}
			catch (Exception exc)
			{
				#region // Catch of try:
				// Rollback:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);

				// Return Bad:
				return TUtils.CProcessException.Process(
					ref mdsFinal
					, exc
					, strErrorCodeDefault
					, alParamsCoupleError.ToArray()
					);
				#endregion
			}
			finally
			{
				#region // Finally of try:
				// Rollback and Release resources:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);
				TDALUtils.DBUtils.ReleaseAllSemaphore(_dbCarSv_Sys, true);

				TUtils.CProcessException.Process(
					ref mdsFinal // mdsFinal
					, _log // log
					, strGWUserCode // strGWUserCode
					, s_myseq.GetNextSeqString() // strLogId
					, strFunctionName // strFunctionName
					, TUtils.CUtils.TidNext(strTid, ref nTidSeq) // strAppTid
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, strLanguageCode // strLanguageCode
					, "" // strRemark
					);
				#endregion
			}
		}
		#endregion

	}
}
